<template>
	<div class="submit-form">
		<el-form :model="formData.submitProp" label-width="100px" ref="formRef">
			<el-form-item :label="item.label" :prop="item.prop" :rules="item.rules" auto-complete="off" v-for="item in formData.formItem" :key="item.id">
				<component :is="`el-${item.ele}`" v-model="formData.submitProp[item.prop]" :type="item.type" :readonly="item.readonly" :placeholder="item.placeholder" />
			</el-form-item>
			<slot name="gender"> </slot>
			<slot name="picture"> </slot>
			<slot name="btn">
				<div class="btn">
					<el-button @click="cancelAddAgent">取消</el-button>
					<el-button @click="createAgent" type="primary">确认</el-button>
				</div>
			</slot>
		</el-form>
	</div>
</template>

<script>
export default {
	props: {
		fromInfo: {
			type: Object,
			defualt: () => {}
		}
	},
	data() {
		return {
			formData: this.fromInfo
		};
	},
	mounted() {
		console.log('formInfo', this.formData);
	},
	methods: {
		cancelAddAgent() {
			this.$refs['formRef'].resetFields();
			this.$emit('cancelAddAgent');
		},
		createAgent() {
			this.$refs['formRef'].validate(valid => {
				if (valid) {
					this.$emit('createAgent', this.formData.submitProp);
				} else {
					this.$message.error('请填写完整信息！');
				}
				this.$refs['formRef'].resetFields();
			});
		}
	}
};
</script>

<style lang="less" scoped>
.submit-form {
	.btn {
		text-align: right;
	}
}
</style>
